// pages/student/course/course.js
var app = getApp();
import {student_active} from "../../../../asserts/js/common/barList";
import {post} from "../../../../asserts/js/request";
import {initCourseInit, getCourseParam} from "../../../../asserts/js/common/shareFun";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    barList: student_active(0),
    top: app.globalData.bottom + 'px',
    course_list: [],
    tabObj: {},
    alter_show: false,
    buttom_title: {
      title1: '舞种',
      title2: "课程类型"
    },
    courseName: "",
    danceKind: [],
    courseLevel: [],
    courseNature: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    this.data.classId= options.classId;

    if(app.globalData.studentInfo.studentId) {
      this.getData();
    } else {
      app.indexCallback = data=>{
        this.getData();
      }
    }
    var obj = initCourseInit(app.globalData.enum_courseTypes, app.globalData.enum_courseKinds, app.globalData.enum_courseNature)
    this.setData({
      classId: options.classId,
      tabObj: obj
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  selectBoxShow: function(){
    this.setData({
      alter_show: true
    })
  },
  alterCancel: function() {
    this.setData({
      alter_show: false
    })
  },
  itemClick: function(e) {
    wx.setStorageSync('courseItem', e.currentTarget.dataset.item)
    wx.navigateTo({
      url: '/pages/student/course/courseDetail/courseDetail'
      + "?classId=" + this.data.classId
    })
  },
  getData: function() {
    var this_ = this;
    post("student-queryCourse",{
      classId: this.data.classId,
      studentId: app.globalData.studentInfo.studentId,
      courseName: this.data.courseName,
      danceKind: this.data.danceKind.join("|"),
      courseKind: this.data.courseLevel.join("|"),
      courseNature: this.data.courseNature.join("|")
    }).then(data => {
      console.log(data);
      this_.setData({
        course_list: data.courseInfo
      })
    }).catch(err => {
      console.log(err);
    })
  },
  init: function(data) {
    if(data < 1000) {
      return data + "";
    }else if(data < 10000) {
      return Math.floor(data/1000*10)/10 + "千";
    }else {
      return Math.floor(data/10000*10)/10 + "万"
    }
  },
  nameChange: function(e) {
    this.setData({
      courseName: e.detail.value
    })
  },
  selectSure: function(e) {
    let this_ = this;
    var paramList = getCourseParam(e.detail.tabList);
    this.setData({
      danceKind: paramList.danceKind,
      courseLevel: paramList.courseLevel,
      courseNature: paramList.courseNature,
      alter_show: false
    }, function(){
      this_.getData()
    })
  },
  navBack : function() {
    wx.navigateBack({
      delta: 0,
    })
  }
})